package com.u3k.app.mid;

import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION;
import android.util.Log;
import com.u3k.app.mid.utils.common.Util;
import com.u3k.app.mid.utils.statistics.StatisticsManager;
import com.u3k.mid.LogUtils;
import com.u3k.mid.ae;
import com.u3k.mid.aw;
import com.u3k.mid.b;
import org.json.JSONObject;

public class HeartbeatManager {
    static final String TAG = "HeartbeatManager";
    private static HeartbeatManager mInstance;
    public Context mContext;

    public HeartbeatManager(Context context) {
        this.mContext = context.getApplicationContext();
    }

    public static HeartbeatManager getInstance(Context context) {
        synchronized (HeartbeatManager.class) {
            try {
                if (mInstance == null) {
                    mInstance = new HeartbeatManager(context);
                }
                HeartbeatManager heartbeatManager = mInstance;
                return heartbeatManager;
            } finally {
                Object obj = HeartbeatManager.class;
            }
        }
    }

    private String getJsonParams(Context context, String str, String str2) {
        String str3 = "";
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("channelId", Util.getChannelId(context));
            jSONObject.put("appId", Util.getAppId(context));
            jSONObject.put("bundleId", Util.getBundleId(context));
            jSONObject.put("shellVer", Util.getShellVersion(context));
            jSONObject.put("middleVer", Util.getMiddleVersion(context));
            String e = aw.e(context);
            String servImei = Util.getServImei(context);
            jSONObject.put("imei", e);
            jSONObject.put("srvImei", servImei);
            String[] c = aw.c(context);
            e = c[0] == null ? "" : c[0];
            LogUtils.a(TAG, "getJsonParams===imsi = " + e);
            jSONObject.put("imsi", e);
            jSONObject.put("brand", Build.BRAND);
            jSONObject.put("model", Build.MODEL);
            jSONObject.put("mac", aw.f(context));
            jSONObject.put("androidVer", VERSION.RELEASE);
            jSONObject.put("gaid", aw.b(context));
            jSONObject.put("aid", aw.a(context));
            if (Util.isRootSystem()) {
                jSONObject.put("hasRoot", 1);
            } else {
                jSONObject.put("hasRoot", 0);
            }
            jSONObject.put("location", Util.getLocationString(context));
            jSONObject.put("netType", aw.l(context));
            jSONObject.put("selfPkgName", Util.getSelfPkgName(context));
            jSONObject.put("installPath", Util.getInstallDir(context));
            jSONObject.put("token", Util.getUserToken(context));
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put(str, new JSONObject(str2));
            jSONObject.put("modules", jSONObject2);
            str3 = jSONObject.toString();
        } catch (Exception e2) {
            LogUtils.LogError(TAG, "getJsonParams>>>", e2);
            StatisticsManager.getInstance().logException(ae.a(), e2);
        }
        LogUtils.a(TAG, "getJsonParams = " + str3);
        return str3;
    }

    private void longLog(String str, String str2, int i) {
        if (str2.length() <= i) {
            LogUtils.LogError(str, str2);
            return;
        }
        Log.d("payne", "longLog   111");
        longLog(str, str2.substring(i), i);
    }

    public void heartbeatRequest(String str, String str2, String str3, HeartbeatListener heartbeatListener) {
        synchronized (this) {
            new b(this, str, str2, str3, heartbeatListener).start();
        }
    }
}
